//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CBaseIndex9.h>
///	@path	~/src/graphics/dx9/
///	@date	2009/01/13
///	@desc	.

#pragma once

#include "xeres.h"

#include "graphics/IVertexIndex.h"
#include "graphics/dx9/CDevice9.h"

namespace xeres {

	/*! 
		\class	CBaseIndex9
		\brief
	*/
	class CBaseIndex9 : public IVertexIndex
	{
	public:

		/// \ctor
		CBaseIndex9( IDirect3DIndexBuffer9 * buffer , size_t count );

		/// \dtor
		virtual ~CBaseIndex9( void );

		DECL_IOBJECT_CLASS( CBaseIndex9 , IVertexIndex );

	public:

		/// \impl
		virtual bool OnLostDevice( void );

		/// \impl
		virtual bool OnResetDevice( RefWeak<IDevice> device );

		/// \name Index Buffer Interface
		//@{

		/// \impl
		virtual size_t GetCount( void );

		/// \impl
		virtual size_t GetSize( void );

		/// \impl
		virtual bool IsWritable( void );

		/// \impl
		virtual bool IsReadable( void );

		/// \impl
		virtual bool Map( bool discard , ResourceMap& data );

		/// \impl
		virtual bool ReadBack( ResourceMap& data , bool readonly );

		/// \impl
		virtual bool Unmap( void );

		/// \impl
		virtual IUnknown * GetVertexInterface( void );

		/// \impl
		virtual IUnknown * GetIndexInterface( void );

		/// \impl
		virtual DXFormat GetFormat( void );

		/// \impl
		virtual void ApplyIndex( RenderContext& rc );

		//@}

	protected:

		//@ data
		IDirect3DIndexBuffer9 *		m_pBuffer;
		size_t						m_count;
		D3DINDEXBUFFER_DESC			m_desc;
	};
	
} // namespace xeres
